#!/usr/bin/env python
# coding:utf-8

from tornado import ioloop
import tornado.netutil
import tornado.options
import tornado.httpserver
from tornado.options import define, options, parse_command_line
# from motorengine import connect


import config

define("port", group='Webserver', type=int, default=8011, help="Run on the given port")
define("subpath", group='Webserver', type=str, default="", help="Url subpath (such as /nebula)")
define('unix_socket', group='Webserver', default=None, help='Path to unix socket to bind')


def main():

    # Star application
    from application import app

    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    print('Server is running at http://127.0.0.1:%s%s' % (options.port, options.subpath))
    print('Quit the server with Control-C')

    tornado.ioloop.IOLoop.instance().start()


if __name__ == "__main__":
    main()
